package ajo;

import static org.junit.Assert.assertTrue;
import robocode.control.events.TurnEndedEvent;
import robocode.control.snapshot.IRobotSnapshot;
import robocode.control.testing.RobotTestBed;

/**
 * This tests that BattleBot moves when it detects an energy drop, so as to avoid enemy bullets.
 * 
 * @author Joshua Antonio
 */
public class TestBattleBotMovement extends RobotTestBed {
  boolean init = true;
  double xCoor;
  double yCoor;
  double enemyEnergy;

  /**
   * Specifies that Fire and BattleBot are to be matched up in this test case.
   * 
   * @return The comma-delimited list of robots in this match.
   */
  @Override
  public String getRobotNames() {

    return "sample.Fire,ajo.BattleBot";
  }

  /**
   * This test runs for 10 rounds.
   * 
   * @return The number of rounds.
   */
  @Override
  public int getNumRounds() {
    return 10;
  }

  /**
   * At the end of each turn, checks that the enemy's energy level is the same as the previous turn.
   * If it is not, that is an energy drop, so we check that BattleBot has moved (it's X and Y
   * coordinates have changed from the previous turn.
   * 
   * @param event Info about the current state of the battle.
   */
  @Override
  public void onTurnEnded(TurnEndedEvent event) {
    IRobotSnapshot enemyBot = event.getTurnSnapshot().getRobots()[0];
    IRobotSnapshot battleBot = event.getTurnSnapshot().getRobots()[1];
    if (this.init) {
      this.xCoor = battleBot.getX();
      this.yCoor = battleBot.getY();
      this.enemyEnergy = enemyBot.getEnergy();
      this.init = false;
    }
    else {
      if (enemyEnergy != enemyBot.getEnergy()) {
        assertTrue((battleBot.getX() != this.xCoor && battleBot.getX() != this.yCoor));
      }
    }
  }
}